-- =============================================  
-- Author:  Raul Esquer  
-- Create date: 11/06/2012  
-- Description: Obtener un listado de Tecnologias.  
-- [Tecnology_R] '',1, 11, 'Name', 'ASC' 
-- =============================================  
CREATE PROCEDURE [dbo].[Tecnology_R] 
@Name NVARCHAR(200),
@Start INT, 
@Limit INT, 
@Order NVARCHAR(50),
@Direction NVARCHAR(5)
AS  
BEGIN  
 SET NOCOUNT ON;       
 
		SELECT  ROW_NUMBER() OVER ( ORDER BY 
					 CASE WHEN @Order = 'Name'AND @Direction = 'ASC' THEN Nombre END ASC,	      					 
					 CASE WHEN @Order = 'Name'AND @Direction = 'DESC' THEN Nombre END DESC	      
					 ) AS RowNum, 
				T.Id, T.Nombre
		  INTO #Tecnologia
		  FROM Tecnologia T 
		  WHERE (Nombre LIKE '%'+@Name+'%' OR @Name = '')			
			AND T.Activo = 1					
	Select COUNT(id)AS TotalReg From #Tecnologia
	 
	 
	 SELECT Id, Nombre
		FROM    #Tecnologia
		WHERE   RowNum BETWEEN @Start + 1 AND (@Start + @Limit)

	DROP TABLE #Tecnologia		
	
 SET NOCOUNT OFF  
END  


